package com.shouhuobao.visit;


import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.collectplus.express.R;
import com.collectplus.express.model.VisitDoorBean;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.lang.Str;

/**
 * Created by lidandan on 2017/12/14.
 */

public class VisitHistoryRecordAdapter extends BaseAdapterExt<VisitDoorBean> {

    public VisitHistoryRecordAdapter(ArrayList<VisitDoorBean> items, Activity context) {
        super(items, context);
        //空白显示
        if (context instanceof VisitHistoryRecordActivity) {
            setEmptyView(R.layout.visit_history_empty);
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.visit_history_record_item, parent, false);
            holder.mAddressTv = (TextView) convertView.findViewById(R.id.address_tv);
            holder.mAddressDetailTv = (TextView) convertView.findViewById(R.id.address_detail_tv);
            holder.mAddressPhoneTv = (TextView) convertView.findViewById(R.id.address_phone_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        VisitDoorBean visitDoorBean = getItem(position);
        holder.mAddressTv.setText(visitDoorBean.getBuildName());
        holder.mAddressDetailTv.setText(visitDoorBean.getAddress());
        if (Str.isEmpty(visitDoorBean.getPhone())) {
            holder.mAddressPhoneTv.setVisibility(View.INVISIBLE);
        } else {
            holder.mAddressPhoneTv.setVisibility(View.VISIBLE);
            holder.mAddressPhoneTv.setText("联系电话：" + visitDoorBean.getPhone());
        }
        return convertView;
    }

    public class ViewHolder {
        TextView mAddressTv;
        TextView mAddressDetailTv;
        TextView mAddressPhoneTv;
    }
}
